package com.example.su_shi_tan_home

import android.annotation.SuppressLint
import android.content.Context
import android.widget.Button
import android.widget.TextView
import com.alibaba.fastjson.JSON
import com.example.library_common.utils.normalShortToast
import com.example.su_shi_tan_bas_lib.networking.RestClient
import com.lxj.xpopup.core.CenterPopupView
import java.lang.Exception

class LightingPop(context: Context):CenterPopupView(context) {


    var data:String?=""

    private val ld_Tv by lazy {
        findViewById<TextView>(R.id.ld_Tv)
    }

    private val st_Tv by lazy {
        findViewById<TextView>(R.id.st_Tv)
    }

    private val lightingBtn by lazy {
        findViewById<TextView>(R.id.lightingBtn)
    }


    override fun getImplLayoutId(): Int {
        return R.layout.lighting_pop
    }

    override fun onCreate() {
        super.onCreate()
//        RestClient.builder()
//            .url(R.string.sign_integral)
//            .success {
//                parseData(it)
//            }.failure {
//                normalShortToast(context,R.string.net_work_failed)
//                dismiss()
//            }.error { _, msg ->
//                normalShortToast(context,msg)
//                dismiss()
//            }.build().post()
        parseData(data)
    }

    @SuppressLint("SetTextI18n")
    private fun parseData(it: String?) {
        try {
            val obj = JSON.parseObject(it)
            ld_Tv.text="LD:  ${obj["integral"].toString()}"
            st_Tv.text="ST:  ${obj["st"].toString()}"
            lightingBtn.setOnClickListener {
                sendData()
            }
        }catch (e:Exception){
            e.printStackTrace()
        }

    }

    private fun sendData() {
        dismiss()
    }

}